<!--
 * @Description:
 * @Author bianpengfei
 * @create 2022/11/8 22:17
 -->
<template>
  <el-dialog
    v-if="_visible"
    :visible.sync="_visible"
    append-to-body
    width="700px"
    :title="_title"
    top="54px"
    custom-class="el-dialog--xbm2o0s98"
    :close-on-click-modal="false"
  >
    <div class="py-8px pr-12px">
      <el-form ref="form" :model="form" label-width="100px">
        <el-form-item
          prop="content"
          label="角色编码"
          :rules="[{ required: true, message: '请输入角色编码', trigger: 'blur' }]"
        >
          <el-input v-model="form.content" placeholder="输入角色编码" clearable></el-input>
        </el-form-item>

        <el-form-item
          prop="content"
          label="角色名"
          :rules="[{ required: true, message: '请输入角色名', trigger: 'blur' }]"
        >
          <el-input v-model="form.content" placeholder="输入角色名" clearable></el-input>
        </el-form-item>

        <el-form-item label="角色描述">
          <el-input
            v-model="form.content"
            type="textarea"
            placeholder="输入角色描述"
            clearable
            :autosize="{ minRows: 2, maxRows: 6 }"
          ></el-input>
        </el-form-item>

        <template>
          <div class="flex justify-center">
            <el-button type="primary" @click="onSubmit">保存</el-button>
            <el-button @click="_visible = false">关闭</el-button>
          </div>
        </template>
      </el-form>
    </div>
  </el-dialog>
</template>

<script>
import { asyncTo } from '@bianpengfei/utils'

export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    },

    model: {
      type: [String, Number],
      default: 1 // 1 新增 2 编辑
    }
  },

  data() {
    return {
      form: {
        title: '',
        content: ''
      }
    }
  },

  computed: {
    _title() {
      const conf = {
        1: '新增角色',
        2: '编辑角色'
      }
      return conf[String(this.model)]
    },

    _visible: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', val)
      }
    }
  },

  watch: {},

  created() {},

  mounted() {
    this.$once('hook:beforeDestroy', () => {
      // this.removeEvents()
    })
  },

  methods: {
    onReset() {
      this.form = {
        ...this.form,
        title: '',
        content: ''
      }
    },

    async onSubmit() {
      const [res, err] = await asyncTo(this.$refs.form.validate())
      if (res) {
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.page {
}
</style>

<style lang="scss">
.el-dialog--xbm2o0s98 {
  .el-descriptions {
    .el-descriptions__body {
      .el-descriptions-item__label {
        color: #000;
        font-size: 13px;
      }
    }
  }
}
</style>
